package com.kuang.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration //配置类
public class MyMvcConfig implements WebMvcConfigurer {

    @Override
    public void addViewControllers(ViewControllerRegistry registry){
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/index.html").setViewName("index");
        registry.addViewController("/main.html").setViewName("dashboard"); //难免游览器登录信息暴露
    }

    //把国际化主键注入到bean中，这样自定义的国际化主键就生效了
    /**
     * <a class="btn btn-sm" th:href="@{/index.html(l='zh_CN')}">中文</a>
     * <a class="btn btn-sm" th:href="@{/index.html(l='en_US')}">English</a>
     */
    @Bean
    public MyLocaleResolver localeResolver(){
        return new MyLocaleResolver();
    }

    //拦截器

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LogHandlerInterceptor())
                .addPathPatterns("/**").excludePathPatterns("/index.html","/","/user/login");//excludePathPatterns,拦截什么请求
    }
}
